﻿using System;
using System.Collections.Generic;

namespace dictionaryconverter
{

    public  class DictionaryConverter
    {

        public static Dictionary<string, string> ToDictionary(string text)
        {
            var keyvalues = ZerlegeKonfiguration(text);
            var dictionaryeintraege = ZerlegeKeyValue(keyvalues);
            return CreateDictionary(dictionaryeintraege);
        }

        internal static String[] ZerlegeKonfiguration(String text)
        {
            var keyvalues = text.Split(';');
            return keyvalues;
        }


        internal static string[][] ZerlegeKeyValue(string[] keyvalues)
        {
            var dictionaryeintraege = new string[keyvalues.Length][];

            for (var i = 0; i < keyvalues.Length; i++)
            {
                var keyvalue = keyvalues[i].Split('=');
                dictionaryeintraege[i] = keyvalue;
            }


            return dictionaryeintraege;
        }


        internal static Dictionary<string, string> CreateDictionary(string[][] dictionaryeintraege)
        {

            var dic = new Dictionary<string, string>();

            for (int i = 0; i < dictionaryeintraege.Length ; i++)
            {
                dic.Add(dictionaryeintraege[i][0], dictionaryeintraege[i][1]);
            }


            return dic;
        }
    }
}
